package com.mrx.xfriendship.service;

import com.mrx.commons.annotations.XLog;
import com.mrx.commons.util.asserts.Asserts;
import com.mrx.xfriendship.converter.CommentConverter;
import com.mrx.xfriendship.dao.CommentMapper;
import com.mrx.xfriendship.dao.PostMapper;
import com.mrx.xfriendship.model.vo.CommentVO;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author Mr.X
 * @since 2023-01-14 10:07
 */
@XLog
@Service
@DubboService
public class CommentServiceImpl implements ICommentService {

    @Resource
    private CommentMapper commentMapper;

    @Resource
    private CommentConverter commentConverter;

    @Resource
    private PostMapper postMapper;

    @Override
    public void postComment(Integer id, Integer userId, CommentVO comment) {
        Asserts.POST_NOT_EXISTS.checkNotNull(postMapper.selectByPrimaryKey(id));
        commentMapper.insertSelective(commentConverter.toPO(id, userId, comment));
    }

}
